//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ny.demo530;

import com.ny.demo.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class TestConnection {
    private static final String URL = "jdbc:mysql://localhost:3306/userdb";
    private static final String username = "root";
    private static final String password = "123456";



    public void addEmployee(Employee employee) throws SQLException {
        Connection conn = DriverManager.getConnection(URL, username, password);
        String sql = "insert into user(username,age,number,password) values(?,?,?,?)";
        PreparedStatement pstm = conn.prepareStatement(sql);

        pstm.setString(1, employee.getName());
        pstm.setInt(2, employee.getAge());
        pstm.setString(3, employee.getNumber());
        pstm.setString(4, employee.getPassword());
        int i = pstm.executeUpdate();
        if (i > 0) {
            System.out.println("注册成功");
        } else {
            System.out.println("注册失败");
        }
    }
    public static void main(String[] args) throws SQLException {

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名");
        String username = scanner.next();
        System.out.println("请输入年龄");
        int age = scanner.nextInt();
        System.out.println("请输入工号");
        String number = scanner.next();
        System.out.println("请输入密码");
        String password = scanner.next();
        Employee  employee = new Employee(username,age,number,password);
        TestConnection testConnection = new TestConnection();
        testConnection.addEmployee(employee);
    }
}
